import httpFetch from 'share/httpFetch';
import {message} from "antd";

const AirReportServer = function (context) {
  return {
    // 基础信息
    async getReportBaseData(params){
      try {
        context.setState({loading: true});
        const response = await httpFetch.post('/report/flight/queryFlightTicketPriceReport', params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading: false});
      }
    },
    // 表格详细数据
    async getReportDetailData(params, type){
      try {
        context.setState({loading: true});
        let url = type === 'm' ? '/report/flight/queryMonthByMonthChartReport' : '/report/flight/queryQuarterChartReport';
        const response = await httpFetch.post(url, params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading: false});
      }
    },
    // 提前天数预订分析
    async getDayAnalysisData(params){
      try {
        context.setState({loading3: true});
        const response = await httpFetch.post('/report/flight/queryFlightBookingInAdvancedDaysDetailReport', params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading3: false});
      }
    },
    // 承运商分析
    async getDayAnalysisSupplierData(params){
      try {
        context.setState({loading2: true});
        const response = await httpFetch.post('/report/flight/queryFlightSupplierAnalysisReport', params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading2: false});
      }
    },
  }
}

const dealWithErrorMes = (err) => {
  message.error(`${err.response.data.message}`);
}

export default AirReportServer;
